package com.hyk.utils;

import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;

@Slf4j
public class UserUtils {

    public static Long getUser() {
        String string = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
        try {
            long l = Long.parseLong(string);
            return l;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取user失败");
            throw new ApiException("获取user失败");
        }

    }

}
